﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class LotteryJackpotAdd : AdminpageBase
{ 
    protected string ctype = ReadRequest.RequestString("t");
    protected long id = ReadRequest.RequestLong("id");
    protected Model.LotteryJackpot model = new Model.LotteryJackpot(); 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            inidata();
        }
    }
    private void inidata()
    {
        try
        {
            if (ctype != null && "edit".Equals(ctype))
            {
                model = BLL.LotteryJackpot.GetModel(id);
                if (model != null)
                {
                    textQS.Text = model.LotteryQs;
                    txtNo.Text = model.LotteryMoney.ToString(); 
                    caipiaoType.SelectedValue = model.LotteryType.ToString(); 
                }
            }
            else
            {
                ctype = "ad";
            }
        }
        catch
        {
            ctype = "ad";
        }
    }

    //提交按钮事件
    protected void btn_submit_Click(object sender, EventArgs e)
    {
        save_Newscont();
    }
    private void save_Newscont()
    {
        //获取登录信息
        Model.Manageadmin loginUserInfo_cur = BLL.CMember.ManageadminLoginInfo();
        //没有登录
        if (loginUserInfo_cur == null)
        {
            alertmessageAndGoback("保存失败");
            return;
        }
        if (ctype != null && "edit".Equals(ctype))
        {

            Model.LotteryJackpot model = BLL.LotteryJackpot.GetModel(id);
            if (model != null)
            {
                model.LotteryMoney = decimal.Parse(txtNo.Text.ToString());
                if ((new DateTime()).Equals(model.AddTime))
                {
                    model.AddTime = DateTime.Now;
                }

                if (BLL.LotteryJackpot.Update(model) > 0)
                {
                    alertmessageAndGo("保存成功！", "/manage/LotteryJackpot.aspx");
                    return;
                }
                else
                {
                    alertmessageAndGoback("保存失败");
                    return;
                }
            }
        }
        else
        {
            Model.LotteryJackpot model = new Model.LotteryJackpot();
            model.LotteryType = int.Parse(caipiaoType.SelectedValue);
            model.LotteryQs = textQS.Text;
            model.LotteryMoney = decimal.Parse(txtNo.Text.ToString());
            model.AddTime = DateTime.Now;
            if (BLL.LotteryJackpot.Add(model) > 0)
            {
                alertmessageAndGo("保存成功！", "/manage/LotteryJackpot.aspx");
                return;
            }
            else
            {
                alertmessageAndGoback("保存失败");
                return;
            }
        }
    }
}